home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / foot.cpp < prev    next >
C/C++ Source or Header  |  1996-03-07  |  13KB  |  617 lines

  1. /******************************************************************************
  2. ******************************************************************************/
  3. // 
  4. // Actua Soccer.   (Token Main Routine) 1.9.94
  5. //
  6. //    Programmed by Andy Findlay.
  7. //
  8. /******************************************************************************
  9. ******************************************************************************/
  10.  
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13.  
  14. // Audio includes...
  15. #include "config.h"                            // Config file
  16. #include "basemem.h"                            //
  17. #include "sos.h"                                // SOS stuff
  18. #include "timer.h"                            // Timers for Audio
  19. #include "digi.h"                                // Digital Sound
  20. #include "midi.h"                                // MIDI Sound
  21. #include "audio.h"                            // SOS header
  22.  
  23. #include "global.h"
  24. #include "3deng.h"
  25. #include "defines.h"
  26. #include "mouse.h"
  27. #include "front.h"
  28. #include "eurofrnt\euro_int.h"
  29. #include "mallocx.h"
  30.  
  31. #ifdef ECTS
  32. extern void write_config_file();
  33. #endif
  34.  
  35. struct goal_info
  36. {
  37.     char used;
  38.     int scorer;
  39.     int time;
  40. };
  41.  
  42. typedef struct
  43. {
  44.     goal_info goal_data;
  45. } goal_table;
  46.  
  47. goal_table goals[3*32]={0,0,0};
  48.  
  49. extern void    claim_key_int(void);
  50. extern void    release_key_int(void);
  51. extern char practice;
  52.  
  53. // NETWORK.C
  54. extern "C" void read_joystick(char j,int *x, int *y, int *sw);
  55. extern "C" void read_joy1(int *x, int *y, int *sw);
  56. extern "C" void read_joy2(int *x, int *y, int *sw);
  57. extern "C" void calibrate_joy(char j,unsigned short *x,unsigned short *y);
  58. extern "C" void calibrate_logpad(unsigned short *x,unsigned short *y);
  59. extern "C" void get_joy_dir1(int *x,int *y,int *f);
  60. extern "C" void get_joy_dir2(int *x,int *y,int *f);
  61. extern "C" void get_user_inputs();
  62. extern "C" void process_user_inputs();
  63.  
  64. extern "C" volatile int Teams[MAX_NET_USERS],Players[MAX_NET_USERS];
  65. extern "C" volatile int net_quit;
  66. extern "C" volatile char paused;
  67. extern "C" volatile char pause_request;
  68. extern "C" volatile char keys[256];
  69. extern "C" volatile char key_togs[256];
  70. extern "C" unsigned char machine_no;
  71.  
  72. extern "C" void NetTest(void);
  73. extern "C" void Network_Play_Ready(void);
  74. extern "C" void Quit_Network_Play(void);
  75.  
  76. extern "C" void __far nethandler(void);
  77. extern "C" unsigned int NetworkHandle;
  78. extern "C" short wConsoleNode;
  79. extern "C" int network_on;
  80. extern "C" volatile int count;
  81. extern "C" volatile int tick;
  82. extern "C" volatile int ftick;
  83.  
  84. extern "C" volatile int writeptr;
  85. extern "C" volatile int readptr;
  86.  
  87. extern "C" int game_speed;        // Currently declared in network.c
  88. extern "C" char old_mf;
  89. extern "C" char logpad_on;
  90. extern "C" char joystick1_on;
  91. extern "C" char joystick2_on;
  92. extern "C" unsigned short joy1_cnt_x,joy1_cnt_y;
  93. extern "C" unsigned short joy2_cnt_x,joy2_cnt_y;
  94. extern "C" int joy1_max_x,joy1_max_y,joy1_min_x,joy1_min_y;
  95. extern "C" int joy2_max_x,joy2_max_y,joy2_min_x,joy2_min_y;
  96.  
  97. extern "C" char calibrated_1,calibrated_2;
  98.  
  99. // Externed game functions...
  100. extern void add_team_user(short t,short c);
  101. extern void add_fixed_user(short p,short c);
  102. extern void init_keyboard();
  103. extern void init_users();
  104. extern void init_team();
  105. extern short conv_conts_back(char c);
  106.  
  107. extern setup_info setup;
  108. extern short rand_seed;
  109. extern int match(int argc, char **argv);
  110. match_data match_info;
  111. extern team_info game_data[];
  112.  
  113. extern int players;
  114. extern int avg1_rate,avg1_power,avg1_bcontrol,avg1_flair,
  115.         avg1_vision,avg1_accuracy,avg1_fitness,avg1_disc;
  116.  
  117. extern int avg2_rate,avg2_power,avg2_bcontrol,avg2_flair,
  118.          avg2_vision,avg2_accuracy,avg2_fitness,avg2_disc;
  119.  
  120.  
  121. extern char audio_version;
  122. extern char need_result;
  123. extern short injury_time;
  124. extern "C" int num_of_users;    // Currently in network.c
  125.  
  126. extern char say_names;
  127. extern "C" volatile char net_half;
  128.  
  129. extern "C" void foot_init_net();
  130. extern "C" void foot_uninit_net();
  131.  
  132. extern int performance;
  133.  
  134. int w95;
  135.  
  136. short no_front_users;
  137.  
  138. /******************************************************************************
  139. *****************************************************************************/
  140.  
  141. void mem_test()
  142. {
  143.     int i=get_mem_info();
  144.     printf("Free memory = %d\n",i);
  145.      setup.M8=(i>=MEM8);
  146.     if (setup.verbose)
  147.         if (setup.M8)
  148.             puts("Initialising 8 meg game");
  149.         else
  150.         {
  151.             puts("Initialising 4 meg game");
  152.             printf("Need to free %d more bytes to run 8 meg version\n",MEM8-i);
  153.         }
  154. }
  155.  
  156. /******************************************************************************
  157. *****************************************************************************/
  158.  
  159. int go_audio()
  160. {
  161. // Initialise Audio Config...
  162.     
  163.     if(ReadConfigFile())
  164.         {
  165.         printf("Error! Cannot read Config File.\n");
  166.         return(EXIT_FAILURE);
  167.         }
  168.  
  169.     if(InitialiseDIGI(22050,IDF_VERBOSE))            // Initialise Digital Sound Drivers
  170.         return(EXIT_FAILURE);
  171.  
  172.     return(FALSE);
  173. }
  174.  
  175. /******************************************************************************
  176. ******************************************************************************/
  177.  
  178. // Process command line options...
  179.  
  180. void get_command_line(int argc, char **argv)
  181. {
  182.     short opt,id;
  183.  
  184.     for (int i=1;    i<argc;    i++)
  185.     {
  186.         opt=-1;
  187.         id=100;
  188.  
  189. // Look for switch!
  190.         if (!strcmp(argv[i],"-i"))
  191. // Inputs...
  192.         {
  193.             if (!strcmp(argv[i+1],"j1"))
  194.                 opt=JOY1_CTRL;
  195.             if (!strcmp(argv[i+1],"j2"))
  196.                 opt=JOY2_CTRL;
  197.             if (!strcmp(argv[i+1],"k1"))
  198.                 opt=KEY1_CTRL;
  199.             if (!strcmp(argv[i+1],"k2"))
  200.                 opt=KEY2_CTRL;
  201.             if (!strcmp(argv[i+1],"m"))
  202.                 opt=MOUSE_CTRL;
  203.             if (!strcmp(argv[i+1],"lp"))
  204.                 opt=LOGPAD_CTRL;
  205.             if (!strcmp(argv[i+1],"g1"))
  206.                 opt=GRAV1_CTRL;
  207.             if (!strcmp(argv[i+1],"g2"))
  208.                 opt=GRAV2_CTRL;
  209.             if (!strcmp(argv[i+1],"n"))
  210.                 opt=NET_CTRL;
  211.  
  212.             if (opt>0)
  213. // Look for user id!
  214.             {
  215.                 if (!strcmp(argv[i+2],"a"))
  216.                     id=TEAM_A;
  217.                 else
  218.                     if (!strcmp(argv[i+2],"b"))
  219.                         id=TEAM_B;
  220.                     else
  221.                     {
  222.                         id=atoi(argv[i+2]);
  223.                         if ((id<1) || (id>players) || (id==1) || (id==12))
  224.                             id=100;
  225.                     }
  226.  
  227.                 i+=2;
  228.             }
  229.             if (id==100)
  230.                 i=argc;
  231.             else
  232.             {
  233.                 if (id<0)
  234.                 {
  235.                     if (id==-1)
  236.                         game_data[setup.team_a].player_control+=1<<no_front_users;
  237.                     else
  238.                         game_data[setup.team_b].player_control+=1<<no_front_users;
  239.  
  240.                     match_info.control_methods[no_front_users++]=conv_conts_back(opt);
  241.                 }
  242.                 else
  243.                     add_fixed_user(id,opt);
  244.  
  245. #ifndef FRONT_END
  246.                 if (opt==JOY1_CTRL)
  247.                     joystick1_on=TRUE;
  248.                 if (opt==JOY2_CTRL)
  249.                     joystick2_on=TRUE;
  250.                 if (opt==LOGPAD_CTRL)
  251.                     logpad_on=TRUE;
  252. #endif
  253.             }
  254.         }
  255.         
  256.         if (!strcmp(argv[i],"-s"))
  257. // Stats...
  258.         {
  259.             if (!strcmp(argv[i+1],"ds"))
  260.                 opt=0;
  261.             if (!strcmp(argv[i+1],"vi"))
  262.                 opt=1;
  263.             if (!strcmp(argv[i+1],"bc"))
  264.                 opt=2;
  265.             if (!strcmp(argv[i+1],"sp"))
  266.                 opt=3;
  267.             if (!strcmp(argv[i+1],"fl"))
  268.                 opt=4;
  269.             if (!strcmp(argv[i+1],"ac"))
  270.                 opt=5;
  271.             if (!strcmp(argv[i+1],"pp"))
  272.                 opt=6;
  273.             if (!strcmp(argv[i+1],"st"))
  274.                 opt=7;
  275.  
  276.             if (opt>=0)
  277.             {
  278.                 if (!strcmp(argv[i+2],"a"))
  279.                 {
  280.                     int avg=atoi(argv[i+3]);
  281.                     if (avg>0 && avg<129)
  282.                     {
  283.                         id=0;
  284.                         switch(opt)
  285.                         {
  286.                             case(0):
  287.                                 avg1_disc=avg;
  288.                                 break;
  289.  
  290.                             case(1):
  291.                                 avg1_vision=avg;
  292.                                 break;
  293.  
  294.                             case(2):
  295.                                 avg1_bcontrol=avg;
  296.                                 break;
  297.  
  298.                             case(3):
  299.                                 avg1_rate=avg;
  300.                                 break;
  301.  
  302.                             case(4):
  303.                                 avg1_flair=avg;
  304.                                 break;
  305.  
  306.                             case(5):
  307.                                 avg1_accuracy=avg;
  308.                                 break;
  309.  
  310.                             case(6):
  311.                                 avg1_power=avg;
  312.                                 break;
  313.  
  314.                             case(7):
  315.                                 avg1_fitness=avg;
  316.                                 break;
  317.                         }
  318.                     }
  319.                 }
  320.                 else
  321.                 {
  322.                     if (!strcmp(argv[i+2],"b"))
  323.                     {
  324.                         int avg=atoi(argv[i+3]);
  325.                         if (avg>0 && avg<129)
  326.                         {
  327.                             id=0;
  328.                             switch(opt)
  329.                             {
  330.                                 case(0):
  331.                                     avg2_disc=avg;
  332.                                     break;
  333.  
  334.                                 case(1):
  335.                                     avg2_vision=avg;
  336.                                     break;
  337.  
  338.                                 case(2):
  339.                                     avg2_bcontrol=avg;
  340.                                     break;
  341.  
  342.                                 case(3):
  343.                                     avg2_rate=avg;
  344.                                     break;
  345.  
  346.                                 case(4):
  347.                                     avg2_flair=avg;
  348.                                     break;
  349.  
  350.                                 case(5):
  351.                                     avg2_accuracy=avg;
  352.                                     break;
  353.  
  354.                                 case(6):
  355.                                     avg2_power=avg;
  356.                                     break;
  357.  
  358.                                 case(7):
  359.                                     avg2_fitness=avg;
  360.                                     break;
  361.  
  362.                             }
  363.                         }
  364.                     }
  365.                 }
  366.             }
  367.             else
  368.                 id=100;
  369.  
  370.             if (id==100)
  371.                 i=argc;
  372.             else
  373.                 i+=3;
  374.         }
  375.  
  376.         if (!strcmp(argv[i],"-r"))
  377. // Random seed...
  378.         {
  379. #ifdef ECTS
  380.             machine_no=atoi(argv[i+1]);
  381. #else
  382.             rand_seed=atoi(argv[i+1]);
  383. #endif
  384.         }
  385.  
  386.         if (!strcmp(argv[i],"-a"))
  387. // Choose team...
  388.         {
  389.             setup.team_a=atoi(argv[i+1]);
  390.         }
  391.  
  392.         if (!strcmp(argv[i],"-b"))
  393. // Choose team...
  394.         {
  395.             setup.team_b=atoi(argv[i+1]);
  396.             setup.team_b_kit=atoi(argv[i+1]);
  397.         }
  398.     }
  399. }
  400.  
  401. /*
  402. void GOAL_SCORED(int t,int s,int tm)
  403. {
  404. }
  405. */
  406.  
  407. /******************************************************************************
  408. *****************************************************************************/
  409.  
  410. void SubstituePlayers(int a,int b,int c)
  411. {
  412. }
  413.  
  414. /******************************************************************************
  415. *****************************************************************************/
  416.  
  417. /* Front End Emulator */
  418.  
  419. extern char var_start,var_end;
  420. extern void init_joys();
  421.  
  422. void    test_w95()
  423.     {
  424.     //
  425.     union REGS regs;
  426.     struct SREGS sregs;
  427.  
  428.     memset(&sregs,0,sizeof(sregs));        //clr sregs
  429.     regs.w.ax=0x1600;
  430.     int386x(0x2F,®s,®s,&sregs);
  431.  
  432.     w95=regs.w.ax & 0xff;
  433.  
  434.     if (w95==3 || w95==4)
  435.         {
  436.         //running in windows 95!!!
  437.         if (setup.verbose)
  438.             printf("Running windows 95 version\n");
  439.         w95=TRUE;
  440.         }
  441.     else
  442.         {
  443.         if (setup.verbose)
  444.             printf("Running DOS version\n");
  445.         w95=FALSE;
  446.         }
  447.     }
  448.  
  449.  
  450. int main(int argc, char **argv)
  451. {
  452.     w95=0;        // Windows flag!
  453.     test_w95();
  454.  
  455.     no_front_users=0;
  456.      num_of_users=0;
  457.  
  458.     init_joys();
  459.  
  460.     performance=31;            // Pentium speed!
  461.     setup.team_a=36;
  462.     setup.team_b=1;
  463.     setup.team_b_kit=1;
  464.     setup.stadium=setup.team_b;
  465.     setup.start_res=0;
  466.     setup.vidi_type=0;        // 0=norm, 1=filtered
  467.     setup.verbose=0;
  468.     setup.screen_size=0;
  469.     setup.detail.stadia=1;    // 0=simple,1=complex
  470.     setup.detail.pitch=2;    // 0=simple,1=lo,2=hi
  471.     setup.detail.sky=1;        // 0=off,1=on
  472.     setup.detail.players=1;    // 0=simple,1=full
  473.     setup.detail.lines=1;    // 0=simple,1=full
  474.     setup.detail.shadows=1;    // 0=simple,1=full
  475.  
  476. #ifdef ONE_MACHINE
  477. //    game_data[setup.team_a].player_control=1;
  478. //    game_data[setup.team_b].player_control=2;
  479. //    match_info.control_methods[0]=2;
  480. //    match_info.control_methods[1]=0;
  481. #else
  482.     game_data[setup.team_a].player_control=0;
  483.     game_data[setup.team_b].player_control=0;
  484. #endif
  485.  
  486. #ifdef ECTS
  487.     setup.M8=1;
  488. #else
  489.     mem_test();
  490. #endif
  491.  
  492. #ifdef MEG4
  493.     setup.M8=0;
  494. #endif
  495. //    setup.M8=0;
  496.  
  497. // Setup Subs...
  498.     for (int i=11; i<15; i++)
  499.     {
  500.         game_data[setup.team_a].players[i].flags=1;
  501.         game_data[setup.team_b].players[i].flags=1;
  502.     }
  503.  
  504.     InitialiseTimer();            // Initialise timers for sound drivers
  505.     EUROmatch_info.camera=0;
  506.     EUROmatch_info.audio=FALSE;
  507.     EUROmatch_info.timeit=FALSE;
  508.     EUROmatch_info.offside=TRUE;
  509.     EUROmatch_info.bookings=TRUE;
  510.     EUROmatch_info.freekicks=TRUE;
  511.     EUROmatch_info.substitutes=TRUE;
  512.  
  513.     EUROmatch_info.time=3;
  514.     EUROmatch_info.tac_1=0;
  515.     EUROmatch_info.tac_2=0;
  516.     match_info.CompetitionType=2;
  517. //    match_info.CompetitionType=PRACTICE;
  518. //    match_info.CompetitionType=PENALTIES;
  519.     EUROmatch_info.crowd=0x1fff;    // Crowd noise level!
  520.     EUROmatch_info.pitch=0x7fff;    // Pitch noise level!
  521.     EUROmatch_info.commentary=0x7fff;    // Commentary level!
  522.     EUROmatch_info.master=0x7fff;    // Master noise level!
  523.     EUROmatch_info.referee_vision=120;
  524.     EUROmatch_info.referee_discipline=80;
  525.      EUROmatch_info.rand=3523;
  526.     match_info.GameType=0;        // 0 Arcade 1 Simulation...
  527.      match_info.referee=0;
  528.     EUROmatch_info.wind=0;
  529. //    EUROmatch_info.tga_enable=TRUE;
  530.  
  531.     net_half=1;                // Network game time...
  532.  
  533.     say_names=TRUE;
  534.  
  535.     audio_version=EUROmatch_info.audio;
  536.     if (audio_version)
  537.     {
  538.         if (go_audio())
  539.         {
  540.             UnInitialiseTimer();
  541.             return(FALSE);
  542.         }
  543.     }
  544.  
  545.     network_on=0;
  546. // Timer stuff...
  547.  
  548.     ftick=0;
  549.     tick=0;
  550.     count=0;
  551.     game_speed=REAL_SPEED;
  552.     readptr=writeptr=0;
  553.     AddTimer(TIMER_SPEED,nethandler,NetworkHandle);
  554.  
  555.     injury_time=0;
  556.     claim_key_int();
  557.     init_users();
  558.     init_team();
  559.  
  560.     machine_no=1;
  561.     get_command_line(argc,argv);
  562.  
  563.     InitMouse();
  564.     init_keyboard();
  565.     if (logpad_on)
  566.         calibrate_logpad(&joy1_cnt_x,&joy1_cnt_y);
  567.  
  568.     if (joystick1_on)
  569.     {
  570.         calibrate_joy(0,&joy1_cnt_x,&joy1_cnt_y);
  571.         calibrated_1=TRUE;
  572. #ifdef ECTS
  573.         write_config_file();
  574. #endif
  575.     }
  576.  
  577.     if (joystick2_on)
  578.     {
  579.         calibrate_joy(1,&joy2_cnt_x,&joy2_cnt_y);
  580.         calibrated_2=TRUE;
  581. #ifdef ECTS
  582.         write_config_file();
  583. #endif
  584.     }
  585.  
  586. #ifndef NET_GAME
  587.     old_mf=TRUE;
  588. #else
  589.     old_mf=FALSE;
  590. #endif
  591.  
  592. #ifdef NET_GAME
  593.     foot_init_net();
  594. #endif
  595.  
  596. /**** Call Game ****/
  597.     match(argc,argv);
  598.  
  599. #ifdef NET_GAME
  600.     foot_uninit_net();
  601. #endif
  602.  
  603.     RemoveTimer(NetworkHandle);
  604.  
  605.     if (audio_version)
  606.     {
  607.         UnInitialiseDIGI();    // Uninitialise SOS
  608.     }
  609.  
  610.     UnInitialiseTimer();
  611.  
  612.     release_key_int();
  613.  
  614.     return(0);
  615. }
  616.  
  617.